from django.db import models
from utils.common_basemodel import BaseModels, ModelRedMethod
# Create your models here.


from user.models import Doctor
from user.models import Department
from user.models import Medicine


class Patient(BaseModels, ModelRedMethod):
    type = (
        (0, '暂未查询'),
        (1, 'O型'),
        (2, 'A型'),
        (3, 'B型'),
        (4, 'AB型'),
    )
    state_type = ((1, '诊断完成,待缴费'), (2, '已缴费'))
    id_care = models.CharField(max_length=32, verbose_name='病人身份证')
    blood_type = models.SmallIntegerField(choices=type, default=0, verbose_name='血型')

    illness_desc = models.TextField(verbose_name='病情描述')
    diagnosis = models.CharField(max_length=64, verbose_name='诊断结果')
    diagnosis_instructions = models.TextField(verbose_name='诊断说明')
    medicine_choice = models.CharField(max_length=32, verbose_name='选择用药')
    is_hospital = models.BooleanField(default=False, verbose_name='建议是否住院')
    family_mobile = models.CharField(max_length=32, null=True, verbose_name='家属联系电话')
    add_time = models.DateTimeField(auto_now_add=True, verbose_name='诊断记录时间')
    state = models.SmallIntegerField(choices=state_type, default=1, verbose_name='诊断记录状态')
    cost = models.CharField(max_length=64, null=True, verbose_name='费用')
    department = models.ForeignKey(to=Department, on_delete=models.SET_NULL, null=True, verbose_name='科室表')
    doctor = models.ForeignKey(to=Doctor, on_delete=models.CASCADE, verbose_name='医生')

    class Meta:
        db_table = 'hospital_patient'
        verbose_name = '病人诊断结果表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name

    def blood_type_name(self):
        return self.get_blood_type_display()

    def is_hospital_name(self):
        if self.is_hospital:
            return '是'
        return '否'

    def state_name(self):
        return self.get_state_display()
